package j3d;

import java.awt.Color;
import java.awt.Font;
import java.awt.Shape;

import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Group;
import javax.media.j3d.LineArray;
import javax.media.j3d.Font3D;
import javax.media.j3d.LineAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Matrix4d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import CAD.MainFrame;
import javax.media.j3d.*;
public class Reference {
	
	float lineLength =(float)- ((1.1* MainFrame.j3d.getMaior())/3);
	Group lineGroup;
	int fontSize=(int) (MainFrame.j3d.getMaior()/4);
	
       TransformGroup createTextX() {
         Appearance textAppear = new Appearance();
         Material m1=new Material();
         m1.setEmissiveColor(150, 150, 150);
         textAppear.setMaterial(m1);
         Font3D font3D = new Font3D(
                  new Font("Helvetica", Font.PLAIN, fontSize),
                                   new FontExtrusion());
         
         
         Text3D textGeom = new Text3D(font3D,
                             new String("X"));
         textGeom.setAlignment(Text3D.ALIGN_CENTER);
         Shape3D textShape = new Shape3D();
         textShape.setGeometry(textGeom);
         textShape.setAppearance(textAppear);
         Transform3D XTransform3D = new Transform3D();
         /////
         
         switch (MainFrame.Face) {
 		case MainFrame.BACKFACE:
 		//	cilinder.translate(-MainFrame.block.width/2, MainFrame.block.length/2,MainFrame.block.height/2);
 			XTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f-lineLength,
					(MainFrame.block.length)*2.5f,
					(MainFrame.block.height)*2.5f));
 			break;
 		case MainFrame.FRONTFACE:
 		//	cilinder.translate(-MainFrame.block.width/2, MainFrame.block.length/2,MainFrame.block.height/2);
 			XTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f-lineLength,
					(MainFrame.block.length)*2.5f,
					(MainFrame.block.height)*2.5f));
 			break;
 		case MainFrame.EASTFACE:
 		//	cilinder.translate(-MainFrame.block.height/2,MainFrame.block.length/2,MainFrame.block.width/2 );
 			XTransform3D.setTranslation(new Vector3f((-MainFrame.block.length)*2.5f-lineLength,
					(MainFrame.block.width)*2.5f,
					(MainFrame.block.height)*2.5f));
 			break;
 		case MainFrame.WESTFACE:
 		//	cilinder.translate(-MainFrame.block.height/2,MainFrame.block.length/2,MainFrame.block.width/2 );
 			XTransform3D.setTranslation(new Vector3f((-MainFrame.block.length)*2.5f-lineLength,
					(MainFrame.block.width)*2.5f,
					(MainFrame.block.height)*2.5f));
 			break;
 		case MainFrame.LOWERFACE:
 			XTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f-lineLength,
					(MainFrame.block.height)*2.5f,
					(MainFrame.block.length)*2.5f));
 			break;
 		case MainFrame.TOPFACE:
 			XTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f-lineLength,
					(MainFrame.block.height)*2.5f,
					(MainFrame.block.length)*2.5f));
 			break;

 		default:
 			System.out.println("erro");
 			break;
 		}
         
         TransformGroup XTrans = new TransformGroup(XTransform3D);
         XTrans.setCapability( XTrans.ALLOW_TRANSFORM_READ );
         XTrans.setCapability(XTrans.ALLOW_TRANSFORM_WRITE );
         XTrans.addChild(textShape);
         return XTrans;
      }
       TransformGroup createTextY() {
           Appearance textAppear = new Appearance();
           Material m1=new Material();
           m1.setEmissiveColor(150, 150, 150);
           textAppear.setMaterial(m1);
           Font3D font3D = new Font3D(
                    new Font("Helvetica", Font.PLAIN, fontSize),
                                     new FontExtrusion());
           Text3D textGeom = new Text3D(font3D,
                               new String("Y"));
           textGeom.setAlignment(Text3D.ALIGN_CENTER);
           Shape3D textShape = new Shape3D();
           textShape.setGeometry(textGeom);
           textShape.setAppearance(textAppear);
           Transform3D YTransform3D = new Transform3D();

           switch (MainFrame.Face) {
           case MainFrame.BACKFACE:
        	   YTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
        			   (MainFrame.block.length)*2.5f,
        			   (MainFrame.block.height)*2.5f+lineLength));
        	   break;
           case MainFrame.FRONTFACE:
        	   YTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
        			   (MainFrame.block.length)*2.5f,
        			   (MainFrame.block.height)*2.5f+lineLength));
        	   break;
           case MainFrame.EASTFACE:
        	   YTransform3D.setTranslation(new Vector3f((-MainFrame.block.length)*2.5f,
        			   (MainFrame.block.width)*2.5f,
        			   (MainFrame.block.height)*2.5f+lineLength));
        	   break;
           case MainFrame.WESTFACE:
        	   YTransform3D.setTranslation(new Vector3f((-MainFrame.block.length)*2.5f,
        			   (MainFrame.block.width)*2.5f,
        			   (MainFrame.block.height)*2.5f+lineLength));
        	   break;
           case MainFrame.LOWERFACE:
        	   YTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
        			   (MainFrame.block.height)*2.5f,
        			   (MainFrame.block.length)*2.5f+lineLength));
        	   break;
           case MainFrame.TOPFACE:
        	   YTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
        			   (MainFrame.block.height)*2.5f,
        			   (MainFrame.block.length)*2.5f+lineLength));
        	   break;

           default:
        	   System.out.println("erro");
        	   break;
           }
           
           TransformGroup YTrans = new TransformGroup(YTransform3D);
           YTrans.setCapability( YTrans.ALLOW_TRANSFORM_READ );
           YTrans.setCapability(YTrans.ALLOW_TRANSFORM_WRITE );
           YTrans.addChild(textShape);
           return YTrans;
        }
       TransformGroup createTextZ() {
           Appearance textAppear = new Appearance();
           Material m1=new Material();
           m1.setEmissiveColor(150, 150, 150);
           textAppear.setMaterial(m1);
           Font3D font3D = new Font3D(
                    new Font("Helvetica", Font.PLAIN, fontSize),
                                     new FontExtrusion());
           Text3D textGeom = new Text3D(font3D,
                               new String("Z"));
           textGeom.setAlignment(Text3D.ALIGN_CENTER);
           Shape3D textShape = new Shape3D();
           textShape.setGeometry(textGeom);
           textShape.setAppearance(textAppear);
           Transform3D ZTransform3D = new Transform3D();
           
           
           ///
           switch (MainFrame.Face) {
   		case MainFrame.BACKFACE:
   		//	cilinder.translate(-MainFrame.block.width/2, MainFrame.block.length/2,MainFrame.block.height/2);
   			ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
  					(MainFrame.block.length)*2.5f-lineLength,
  					(MainFrame.block.height)*2.5f));
   			break;
   		case MainFrame.FRONTFACE:
   		//	cilinder.translate(-MainFrame.block.width/2, MainFrame.block.length/2,MainFrame.block.height/2);
   			ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
  					(MainFrame.block.length)*2.5f-lineLength,
  					(MainFrame.block.height)*2.5f));
   			break;
   		case MainFrame.EASTFACE:
   		//	cilinder.translate(-MainFrame.block.height/2,MainFrame.block.length/2,MainFrame.block.width/2 );
   			ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.length)*2.5f,
  					(MainFrame.block.width)*2.5f-lineLength,
  					(MainFrame.block.height)*2.5f));
   			break;
   		case MainFrame.WESTFACE:
   		//	cilinder.translate(-MainFrame.block.height/2,MainFrame.block.length/2,MainFrame.block.width/2 );
   			ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.length)*2.5f,
  					(MainFrame.block.width)*2.5f-lineLength,
  					(MainFrame.block.height)*2.5f));
   			break;
   		case MainFrame.LOWERFACE:
   			ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
  					(MainFrame.block.height)*2.5f-lineLength,
  					(MainFrame.block.length)*2.5f));
   			break;
   		case MainFrame.TOPFACE:
   			ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
  					(MainFrame.block.height)*2.5f-lineLength,
  					(MainFrame.block.length)*2.5f));
   			break;

   		default:
   			System.out.println("erro");
   			break;
   		}
           /////
        /*   ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
  					(MainFrame.block.height)*2.5f,
  					(MainFrame.block.length)*2.5f-lineLength));*/
           TransformGroup ZTrans = new TransformGroup(ZTransform3D);
           ZTrans.setCapability( ZTrans.ALLOW_TRANSFORM_READ );
           ZTrans.setCapability(ZTrans.ALLOW_TRANSFORM_WRITE );
           ZTrans.addChild(textShape);
           return ZTrans;
        }
	Group createLines(){
			
	lineGroup = new Group();
	
	
	 
	 
	
		ColoringAttributes ca = new ColoringAttributes(new Color3f(0f,255f,0f),
		        ColoringAttributes.SHADE_FLAT);
	Point3f[] dotDashPts = new Point3f[2];
	
	   ///
    switch (MainFrame.Face) {
		case MainFrame.BACKFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.length*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f-lineLength,
						(MainFrame.block.length)*2.5f,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.FRONTFACE:
		
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.length*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f-lineLength,
						(MainFrame.block.length)*2.5f,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.EASTFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.length*2.5f,MainFrame.block.width*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.length)*2.5f-lineLength,
						(MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.WESTFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.length*2.5f,MainFrame.block.width*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.length)*2.5f- lineLength,
						(MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.LOWERFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f-lineLength,
						(MainFrame.block.height)*2.5f,
						(MainFrame.block.length)*2.5f);
			break;
		case MainFrame.TOPFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f-lineLength,
						(MainFrame.block.height)*2.5f,
						(MainFrame.block.length)*2.5f);
			 /*	ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
				(MainFrame.block.height)*2.5f,
				(MainFrame.block.length)*2.5f-lineLength));*/
			break;

		default:
			System.out.println("erro");
			break;
		}
    /////
	
	
	
   /* dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
    dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f-lineLength,
    							(MainFrame.block.height)*2.5f,
    							(MainFrame.block.length)*2.5f);*/
    LineArray dotDash = new LineArray(2, LineArray.COORDINATES);
    dotDash.setCoordinates(0, dotDashPts);
    LineAttributes dotDashLa = new LineAttributes();
    dotDashLa.setLineWidth(4.0f);
    dotDashLa.setLinePattern(LineAttributes.PATTERN_DASH_DOT);
    Appearance dotDashApp = new Appearance();
    dotDashApp.setLineAttributes(dotDashLa);
    dotDashApp.setColoringAttributes(new ColoringAttributes());
    Shape3D dotDashShape = new Shape3D(dotDash, dotDashApp);
  
    lineGroup.addChild(dotDashShape);
    
    dotDashPts = new Point3f[2];
	   ///
    switch (MainFrame.Face) {
		case MainFrame.BACKFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.length*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.length)*2.5f-lineLength,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.FRONTFACE:
		
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.length*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.length)*2.5f-lineLength,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.EASTFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.length*2.5f,MainFrame.block.width*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.length)*2.5f,
						(MainFrame.block.width)*2.5f-lineLength,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.WESTFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.length*2.5f,MainFrame.block.width*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.length)*2.5f,
						(MainFrame.block.width)*2.5f - lineLength,
						(MainFrame.block.height)*2.5f);
			break;
		case MainFrame.LOWERFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f-lineLength,
						(MainFrame.block.length)*2.5f);
			break;
		case MainFrame.TOPFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f-lineLength,
						(MainFrame.block.length)*2.5f);
			 /*	ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
				(MainFrame.block.height)*2.5f,
				(MainFrame.block.length)*2.5f-lineLength));*/
			break;

		default:
			System.out.println("erro");
			break;
		}
    /////
    /*dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
    dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
    							(MainFrame.block.height)*2.5f-lineLength,
    							(MainFrame.block.length)*2.5f);*/
    dotDash = new LineArray(2, LineArray.COORDINATES);
    dotDash.setCoordinates(0, dotDashPts);
    dotDashLa = new LineAttributes();
    dotDashLa.setLineWidth(4.0f);
    dotDashLa.setLinePattern(LineAttributes.PATTERN_DASH_DOT);
    dotDashApp = new Appearance();
    dotDashApp.setLineAttributes(dotDashLa);
    dotDashApp.setColoringAttributes(new ColoringAttributes());
    dotDashShape = new Shape3D(dotDash, dotDashApp);
    lineGroup.addChild(dotDashShape);
    
    dotDashPts = new Point3f[2];
	   ///
    switch (MainFrame.Face) {
		case MainFrame.BACKFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.length*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.length)*2.5f,
						(MainFrame.block.height)*2.5f+lineLength);
			break;
		case MainFrame.FRONTFACE:
		
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.length*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.length)*2.5f,
						(MainFrame.block.height)*2.5f+lineLength);
			break;
		case MainFrame.EASTFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.length*2.5f,MainFrame.block.width*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.length)*2.5f,
						(MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f+lineLength);
			break;
		case MainFrame.WESTFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.length*2.5f,MainFrame.block.width*2.5f,MainFrame.block.height*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.length)*2.5f,
						(MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f+lineLength);
			break;
		case MainFrame.LOWERFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f,
						(MainFrame.block.length)*2.5f+lineLength);
			break;
		case MainFrame.TOPFACE:
			 dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
			 dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
						(MainFrame.block.height)*2.5f,
						(MainFrame.block.length)*2.5f+lineLength);
			 /*	ZTransform3D.setTranslation(new Vector3f((-MainFrame.block.width)*2.5f,
				(MainFrame.block.height)*2.5f,
				(MainFrame.block.length)*2.5f-lineLength));*/
			break;

		default:
			System.out.println("erro");
			break;
		}
    /////
   /* dotDashPts[0] = new Point3f(-MainFrame.block.width*2.5f,MainFrame.block.height*2.5f,MainFrame.block.length*2.5f);
    dotDashPts[1] = new Point3f((-MainFrame.block.width)*2.5f,
								(MainFrame.block.height)*2.5f,
								(MainFrame.block.length)*2.5f-lineLength);*/
    dotDash = new LineArray(2, LineArray.COORDINATES);
    dotDash.setCoordinates(0, dotDashPts);
    dotDashLa = new LineAttributes();
    dotDashLa.setLineWidth(4.0f);
    dotDashLa.setLinePattern(LineAttributes.PATTERN_DASH_DOT);
    dotDashApp = new Appearance();
    dotDashApp.setLineAttributes(dotDashLa);
    dotDashApp.setColoringAttributes(new ColoringAttributes());
    dotDashShape = new Shape3D(dotDash, dotDashApp);
    lineGroup.addChild(dotDashShape);
    
    
	 return lineGroup;
	}
	
	

	
}
